from common import SITE
from database.db import save_categories
from downloader import download

filtered = [
    "首页",
    "2025最新电影",
    "国语配音电影",
    "3D电影",
    "真人秀",
    "MP4手机电影",
    "综艺节目",
    "港台电影",
    "日韩电影",
    "新版6V",
    "印度电影",
    "国产电影",
    "欧洲电影",
    "专题推荐"
]

if __name__ == '__main__':
    resp = download(SITE)
    print(resp.url)
    urls = resp.xpath('//p[@class="bg"]/a/@href').extract()[1:]
    titles = resp.xpath('//p[@class="bg"]/a/text()').extract()[1:]
    urls += resp.xpath('//div[@id="menu"]/p/a/@href').extract()
    titles += resp.xpath('//div[@id="menu"]/p/a/text()').extract()
    for i in range(len(urls)):
        title = titles[i]
        if title not in filtered:
            cate = {
                'url': urls[i],
                'category': titles[i],
                'base_url': resp.url
            }
        save_categories(cate)
